import variables from "admin/styles/element-variables.scss";
import Vue from "vue";

import defaultSettings from "admin/settings";

const { showSettings, tagsView, fixedHeader, sidebarLogo, supportPinyinSearch, title, logo } = defaultSettings;

const state = {
    title: (Vue.ls.get("curr") && Vue.ls.get("curr").schoolName) || title,
    logo: (Vue.ls.get("curr") && Vue.ls.get("curr").logo) || logo,
    theme: variables.theme,
    showSettings,
    tagsView,
    fixedHeader,
    sidebarLogo,
    supportPinyinSearch,
};

const mutations = {
    //统一设置state
    SET_STATE(state, data) {
        Object.assign(state, data);
    },
    CHANGE_SETTING: (state, { key, value }) => {
        // eslint-disable-next-line no-prototype-builtins
        if (state.hasOwnProperty(key)) {
            state[key] = value;
        }
    },
};

const actions = {
    changeSetting({ commit }, data) {
        commit("CHANGE_SETTING", data);
    },
};

export default {
    namespaced: true,
    state,
    mutations,
    actions,
};
